# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=python-setuptools
pkgname=('python3-setuptools' 'python2-setuptools')
pkgver=15.2
pkgrel=1
pkgdesc="Easily download, build, install, upgrade, and uninstall Python packages"
arch=('any')
license=('PSF')
url="http://pypi.python.org/pypi/setuptools"
makedepends=('python' 'python2')
source=("http://pypi.python.org/packages/source/s/setuptools/setuptools-${pkgver}.tar.gz")
md5sums=('a9028a9794fc7ae02320d32e2d7e12ee')

prepare() {
   cd "${srcdir}"

   pushd setuptools-${pkgver}
   popd

   cp -a setuptools-${pkgver}{,-python2}

   cd "${srcdir}"/setuptools-${pkgver}
   sed -i -e "s|^#\!.*/usr/bin/python|#!/usr/bin/python3|" tests/manual_test.py
   sed -i -e "s|^#\!.*/usr/bin/env python|#!/usr/bin/env python3|" setuptools/command/easy_install.py

   cd ../setuptools-${pkgver}-python2
   sed -i -e "s|^#\!.*/usr/bin/python|#!/usr/bin/python2|" tests/manual_test.py
   sed -i -e "s|^#\!.*/usr/bin/env python|#!/usr/bin/env python2|" setuptools/command/easy_install.py
}

build() {
   # Build python 3 module
   cd "${srcdir}"/setuptools-${pkgver}
   python3 setup.py build

   # Build python 2 module
   cd ../setuptools-${pkgver}-python2
   python2 setup.py build
}

check() {
   # Check python3 module
   cd "${srcdir}"/setuptools-${pkgver}
   python3 setup.py test

   # Check python2 module
   cd "${srcdir}"/setuptools-${pkgver}-python2
   python2 setup.py test
}

package_python3-setuptools() {
   depends=('python>=3.3')
   provides=('python3-distribute')
   replaces=('python3-distribute')

   cd "${srcdir}/setuptools-${pkgver}"
   python3 setup.py install --prefix=/usr --root="${pkgdir}" --optimize=1 --skip-build
}

package_python2-setuptools() {
   depends=('python2>=2.7')
   provides=('python2-distribute' 'setuptools')
   replaces=('python2-distribute' 'setuptools')

   cd "${srcdir}/setuptools-${pkgver}-python2"
   python2 setup.py install --prefix=/usr --root="${pkgdir}" --optimize=1 --skip-build
   rm "${pkgdir}/usr/bin/easy_install"
}
